<?php
//二分查找（数组里查找某个元素）

global  $times ;
//$times = 0;
function binSearch($array,  $low, $high, $k){
    global  $times ;
    $times++;
    if ( $low <= $high){
        $mid =  intval(($low+$high)/2 );
        if ($array[$mid] ==  $k){
            return $mid;
        }elseif ( $k < $array[$mid]){
            return  binSearch($array, $low,  $mid-1, $k);
        }else{
            return  binSearch($array, $mid+ 1, $high, $k);
        }
    }
    return -1;
}

$arr = [1,2,3,4,5,6,7,8,9];
binSearch($arr,1,9,6);
echo $times;